package com.aaa.controller;

import com.aaa.entity.LayData;
import com.aaa.entity.User;
import com.aaa.service.TuserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    private TuserService tuserService;


    /**
     * ajax发出的请求  返回数据的时候@ResponBody的注解   返回的是json数据
     * @param session
     * @return
     */
    @RequestMapping("login")
    @ResponseBody
    public LayData login(HttpSession session, User user){
        LayData layData = new LayData();
        User user1=tuserService.login(user);
        if(user1!=null){
            layData.setData(true);
            // 当前的登录的信息 保存到session里面
            session.setAttribute("user",user1);

        }
        return layData;
    }
}
